package com.cjc.controller;

import com.cjc.common.utils.R;
import com.cjc.domain.Device;
import com.cjc.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备Controller
 * @Author: 陈江灿
 * @CreateTime: 2025-01-21
 */
@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 查询设备列表
     * @param device
     * @return
     */
    @GetMapping("/list")
    public R<List<Device>> list(Device device) {
        List<Device> list = deviceService.selectDeviceList(device);
        return R.ok(list);
    }

    /**
     * 根据设备ID获取设备信息
     * @param deviceId
     * @return
     */
    @GetMapping(value = "/{deviceId}")
    public R<Device> getInfo(@PathVariable("deviceId") Long deviceId) {
        return R.ok(deviceService.selectDeviceByDeviceId(deviceId));
    }

    /**
     * 添加设备
     * @param device
     * @return
     */
    @PostMapping("/add")
    public R add(@RequestBody Device device) {
        return R.ok(deviceService.insertDevice(device));
    }

    /**
     * 更新设备信息
     * @param device
     * @return
     */
    @PostMapping("/edit")
    public R edit(@RequestBody Device device) {
        return R.ok(deviceService.updateDevice(device));
    }

    /**
     * 根据设备ID删除设备
     * @param deviceId
     * @return
     */
    @DeleteMapping(value = "/{deviceId}")
    public R remove(@PathVariable("deviceId") Long deviceId) {
        return R.ok(deviceService.deleteDeviceByDeviceId(deviceId));
    }

}
